import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import 'package:schedule_plane/common/net/api.dart';
import 'package:schedule_plane/library/networking/http_error.dart';

import 'package:schedule_plane/library/networking/http_manager.dart';
import 'package:schedule_plane/module/components/carousel_page.dart';
import 'package:schedule_plane/module/home/home_page.dart';
import 'package:schedule_plane/module/message/message_page.dart';

class SCRootPage extends StatefulWidget {
  final String title;
  SCRootPage({Key key, this.title}) : super(key: key);
  @override
  SCRootPageState createState() => new SCRootPageState();
}

class SCRootPageState extends State<SCRootPage> {

  int _currentIndex = 0;

  List<Widget> _pageList = [
    HomePage(),
    MessagePage(),
  ];

  List<BottomNavigationBarItem> _barItem = [
    BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
    BottomNavigationBarItem(icon: Icon(Icons.list), title: Text('新闻')),
  ];

  @override
  Widget build(BuildContext context) {
    _get();
    return new Scaffold(
      body: this._pageList[this._currentIndex],
      bottomNavigationBar:BottomNavigationBar(
        items: _barItem,
        currentIndex: this._currentIndex,
        onTap: (int index){
          setState(() {
            this._currentIndex = index;
          });
        },
        fixedColor: Colors.blueAccent,
        selectedFontSize: 12,
        type: BottomNavigationBarType.fixed,
      ),
      floatingActionButton: FloatingActionButton(
      onPressed: (){
        // Navigator.of(context).pushNamed('MyHome');
        Navigator.push(context, MaterialPageRoute(builder: (context) {
          return CarouselPage();
        }));
      },
      tooltip: 'Increment',
      child: Icon(Icons.add),
    ),
    );
  }
  @override
  void initState() {
    super.initState();
    _get();
  }

  ///get 网络请求
  void _get() async {
    EasyLoading.show();
    HttpManager().post(
      url:Api.exportClubList,
      params: {"PageNo": 1,"PageSize": 1},
      successCallback: (data) {
        EasyLoading.dismiss();
      },
      errorCallback: (HttpError error) {
        EasyLoading.dismiss();
        print(error);
      },
      tag: "clubList",
    );
    // var dio = Dio(BaseOptions(
    //   baseUrl: "http://httpbin.org",
    //   connectTimeout: 5000,
    //   receiveTimeout: 100000,
    //   // 5s
    //   headers: {
    //     // HttpHeaders.userAgentHeader: "dio",
    //     "api": "1.0.0",
    //   },
    //   contentType: Headers.jsonContentType,
    //   // Transform the response data to a String encoded with UTF8.
    //   // The default value is [ResponseType.JSON].
    //   responseType: ResponseType.plain,
    // ));
    //
    // Response response;
    //
    // response = await dio.get("/get");
    // print(response.data);
  }
}